/* 
 * File:   RoutingTable.h
 * Author: lusitanio
 *
 * Created on 19 de Fevereiro de 2012, 18:05
 */

#ifndef ROUTINGTABLE_H
#define	ROUTINGTABLE_H

#include "Graph.h"
#include <vector>
using namespace std;

class RoutingTable {
private:
    vector <vector< pair<int, int> > > tabelaR;
    int custoMaximo;
public:

    RoutingTable() {

    }

    RoutingTable(Graph& grafo, std::vector<Sensor_Info> info, double range, int ponto_acesso) {
        vector<Sensor_Info>::iterator x;
        vector<Sensor_Info>::iterator y;
        pair<int, int> resultado;
        int s, d;
        init(info.size());
        grafo.load_graph(info,range);
        //printf("RoutingTable range: %f PA: %d info.size: %d \n",range,ponto_acesso,info.size());
        for (x = info.begin(); x < info.end(); x++) {
            s = (*x).GetId();
            for (y = info.begin(); y < info.end(); y++) {
                d = (*y).GetId();
                if (s != d){
                    resultado = grafo.dijkstra(s, d);
                    tabelaR[s][d] = resultado;
                    if (ponto_acesso == d)
                        printf("SALTOS(%d,%d): %d \n",s,d,resultado.second);
                    if ((resultado.second > custoMaximo)&&(ponto_acesso == d))
                        custoMaximo = resultado.second;
                }
                    
            }
        } 
        
        puts("FINAL ROUTING TABLE");
      
    }

    void init(int size) {
        vector< pair<int, int> > aux;
        tabelaR = *new vector <vector< pair<int, int> > >(size);
        for (int i = 0; i < size; i++) {
            aux = *new vector< pair<int, int> >(size);
            for (int j = 0; j < size; j++) {
                pair<int, int> par = *new pair<int,int>(NULL,NULL);
                //aux.insert(j,par);
                aux.at(j) = par;
                

            }
            tabelaR.at(i) = aux;
        }
        custoMaximo = 0;
    }
    
    pair<int,int> getRoute(int s,int t){
       return  tabelaR[s][t];
    }
    
    int getCustoMaximo() const {
        return custoMaximo;
    }

    void setCustoMaximo(int custoMaximo) {
        this->custoMaximo = custoMaximo;
    }

};

#endif	/* ROUTINGTABLE_H */

